$(function(){
    init();

    function init(){
        brandAll();
    }

    function brandAll(){
        $.ajax({
            url: "http://193.112.55.79:9090/api/getbrand",
            type: "get",
            dataType: "json",
            data:{"brandtitleid":getUrl("brandTitleId")},
            success: function (result) {
                // console.log(result);
                if (result) {
                    let data = result.result;
                    // console.log(result);
                      let html = template("categoryTpl", { arr: data });
                    $(".category-title").html(html);
                } else {
                    console.log("失败", result);

                }

            }
        })

        $.ajax({
            url: "http://193.112.55.79:9090/api/getbrandproductlist",
            type: "get",
            dataType: "json",
            data:{ "brandtitleid":getUrl("brandTitleId")},
            success: function (result) {
                // console.log(result);
                if (result) {
                    let data = result.result;
                    console.log(result);
                      let html = template("productTpl", { arr: data });
                    $(".product-list").html(html);
                } else {
                    console.log("失败", result);

                }

            }
        })

        $.ajax({
            url: "http://193.112.55.79:9090/api/getproductcom",
            type: "get",
            dataType: "json",
            data:{ "productid": getUrl("brandTitleId")},
            success: function (result) {
                // console.log(result);
                if (result) {
                    let data = result.result;
                    console.log(result);
                      let html = template("protitTpl", { arr: data });
                    $(".pl_list").html(html);
                } else {
                    console.log("失败", result);

                }

            }
        })
    }

     // 获取url上的参数 的值
     function getUrl(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURI(r[2]);
        return null;
      }
})